home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
By Popular Request 2.0
/
By Popular Request 2.0 (Arsenal Computer).ISO
/
amiga_6
/
tiffdtyp.lha
/
sources
/
flzw.asm
< prev
next >
Wrap
Assembly Source File
|
1995-05-21
|
4KB
|
161 lines
opt l+
XDEF _UnPackLZW
XREF _StringTable
EOICODE EQU 257
CLEARCODE EQU 256
LEN EQU 4
LASTCHAR EQU 6
FIRSTCHAR EQU 7
; The StringTable entry structure is defined as:
;
; struct StringEntry
; {
; struct StringEntry *OldCode;
; UWORD StringLen;
; UBYTE LastChar;
; UBYTE FirstChar;
; }
; Adds a string in the string table
;
; a1 = &StringTable[CurrentStringEntry]
; a2 = &StringTable[OldCode]
; d0 = Code
; d1 = TabEntries*sizeof(struct StringEntry)
_AddStringToTable
move.l _StringTable,a0
asl.l #3,d0 ; d0 = d0 * sizeof(struct StringEntry)
add.l d0,a0 ; a0 = &StringTable[Code]
cmp.w d1,d0 ; if(Code < TabEntries)
bge.s .NotInTable ; {
move.l LEN(a0),d2 ; d2 = StringTable[Code].FirstChar;
bra.s .Endif ; }
.NotInTable ; else
move.l LEN(a2),d2 ; d2 = StringTable[OldCode].FirstChar;
.Endif
move.l a2,(a1)+ ; StringTable[CurrentStringEntry].OldCode = &StringTable[OldCode]
move.l LEN(a2),(a1)+ ; StringTable[CurrentStringEntry].StringLen = StringTable[OldCode].StringLen
; StringTable[CurrentStringEntry].FirstChar = StringTable[OldCode].FirstChar
; StringTable[CurrentStringEntry].LastChar = StringTable[OldCode].LastChar
addq.w #1,-4(a1) ; StringTable[CurrentStringEntry].StringLen ++;
move.b d2,-2(a1) ; StringTable[CurrentStringEntry].LastChar = StringTable[Code].FirstChar
move.l a0,a2 ; OldCode = Code
addq.w #8,d1 ; TabEntries++
cmp.w #511*8,d1
beq.s .IncCodeLen
cmp.w #1023*8,d1
beq.s .IncCodeLen
cmp.w #2047*8,d1
beq.s .IncCodeLen
rts
.IncCodeLen
addq.w #1,d4
rts
; Write a string to the output buffer
;
; a3 = OutputBuffer
; a0 = &StringTable[Code]
_WriteString
clr.l d2
move.w LEN(a0),d2 ; d2 = StringTable[Code].Len
add.l d2,a3 ; a3 = OutBuf+Len
move.l a3,a5 ; a5 = OutBuf+Len
sub.w #1,d2
.loop ; for(i=0;i<Len;i++)
move.b LASTCHAR(a0),-(a5) ; OutBuf[i]= StringTable[Code].LastChar
move.l (a0),a0 ; a0 = StringTable[Code].OldCode
dbf d2,.loop
rts
; Get the next code from the input buffer
;
; d4 = CodeLen
; d5 = lastbit
; d6 = InCode
; a4 = InBuffer
_GetNextCode
.while
cmp.b d4,d5 ; while( lastbit < CodeLen )
bge .BufferFull ; {
move.b (a4)+,d6 ; InCode.b[3]=*InBuff++;
lsl.l #8,d6 ; InCode.l << = 8;
addq.b #8,d5 ; lastbit +=8;
bra.s .while ; }
.BufferFull
move.b (a4)+,d6 ; InCode.b[3]=*InBuff++;
; lsl.l #8,d6 ; InCode.l << = 8;
sub.b d4,d5 ; lastbit=lastbit - CodeLen
moveq.l #8,d0
sub.b d5,d0 ; d0 = 8 -(lastbit-CodeLen)
lsl.l d0,d6 ; Incode << = 8-(lastbit-CodeLen)
move.l d6,d0
clr.w d0
swap d0 ; Code = InCode.w[0]
and.l #$ffff,d6
lsl.l d5,d6 ; Incode << = lastbit
addq.b #8,d5 ; lastbit +=8
rts
_InitStringTable
move.l #258*8,d1 ; TabEntries = 258
moveq.l #9,d4 ; CodeLen = 9
move.l _StringTable,a1
add.l d1,a1 ; a1 = &StringTable[Currentry]
rts
;
; Unpack a block of LZW data
;
; a0 = InBuffer
; a1 = OutBuffer
_UnPackLZW
movem.l a2-a5/d2-d7,-(a7)
move.l a0,a4 ; a4 = InBuffer
move.l a1,a3 ; a3 = OutBuffer
move.l a1,outbuf ; outbuf = OutBuffer
clr.l d5
clr.l d6
jsr _InitStringTable
.next
jsr _GetNextCode ; d0 = Code
cmp.w #EOICODE,d0
beq .exit
cmp.w #CLEARCODE,d0
bne.s .noclear
jsr _InitStringTable
jsr _GetNextCode ; d0 = Code
cmp.w #EOICODE,d0
beq.s .exit
move.b d0,(a3)+
asl.l #3,d0
move.l _StringTable,a2
add.l d0,a2
bra.s .next
.noclear
jsr _AddStringToTable
jsr _WriteString
bra.s .next
.exit
move.l a3,d0
sub.l outbuf,d0
movem.l (a7)+,a2-a5/d2-d7
rts
outbuf ds.l 1